package com.nuc.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Time    : 2023/4/1 20:59
 * Author  : 王摇摆
 * FileName: com.nuc.worcount.Main.java
 * Software: IntelliJ IDEA 2020.2.2
 * Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
 */

public class Main {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration configuration = new Configuration();
        configuration.set("fs.defalutFS", "file:///");
        configuration.set("mapreduce.framework.name", "local");
        System.setProperty("HADOOP_USER_NAME", "root");

        Job job = Job.getInstance(configuration, "wordCount1");

        job.setJarByClass(Main.class);
        job.setMapperClass(MyMapper.class);
        job.setReducerClass(MyReducer.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        FileInputFormat.setInputPaths(job, new Path("C:\\Users\\Administrator\\Desktop\\Code\\learn_hadoop\\input.txt"));
        FileOutputFormat.setOutputPath(job, new Path("E:\\output\\output10"));

        job.setNumReduceTasks(3);
        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);
    }

}
